package JAVA300.第十章IO;

import java.io.UnsupportedEncodingException;

/**
 * 测试编码解码 字符到字节
 */
public class EncodeDemo {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String msg = "性命生命使命a";
        //字节数组
        byte[] datas = msg.getBytes();
        System.out.println(datas.length);//19=18+1--UTF-8

        byte[] datas1 = msg.getBytes("GBK");//13
        System.out.println(datas1.length);//19=18+1--UTF-8

        //解码
        msg = new String(datas1,0,datas1.length,"UTF-8");
        System.out.println(msg);

    }
}
